﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net.Mail;
using System.IO;

namespace TestProject
{
	[TestClass]
	public class MailMessageParserTest
	{
		[TestMethod]
		public void TestMethodA31()
		{
			//
			//	A.3.1.  Minimum required
			//
			string message =
				@"Date:     26 Aug 76 1429 EDT
				From:     Jones@Registry.Org  
				Bcc:";
			MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(message));

			ExchangeHog.MessageParser.NewParser parser = new ExchangeHog.MessageParser.NewParser();
			MailMessage mm = parser.ExtractMailMessage(ms);
			Assert.IsNotNull(mm);
			Assert.IsNotNull(mm.Headers);
			Assert.IsNotNull(mm.Headers["Date"]);
			Assert.Equals(DateTime.Parse(mm.Headers["Date"]), DateTime.Parse("8/26/1976 14:29"));
			Assert.IsNotNull(mm.From);
			Assert.IsNotNull(mm.From.Address);
			Assert.Equals(mm.From.Address, "Jones@Registry.Org");
		}

		[TestMethod]
		public void TestMethodA31a()
		{
			string message =
				@"Date:     26 Aug 76 1429 EDT
				From:     Jones@Registry.Org
				To:       Smith@Registry.Org";
			MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(message));

			ExchangeHog.MessageParser.NewParser parser = new ExchangeHog.MessageParser.NewParser();
			MailMessage mm = parser.ExtractMailMessage(ms);
			Assert.IsNotNull(mm);
			Assert.IsNotNull(mm.Headers);
			Assert.IsNotNull(mm.Headers["Date"]);
			Assert.Equals(DateTime.Parse(mm.Headers["Date"]), DateTime.Parse("8/26/1976 14:29"));
			Assert.IsNotNull(mm.From);
			Assert.IsNotNull(mm.From.Address);
			Assert.Equals(mm.From.Address, "Jones@Registry.Org");
			Assert.IsNotNull(mm.To);
			Assert.Equals(mm.To.Count, 1);
			Assert.Equals(mm.To[0].Address, "Smith@Registry.Org");
		}

		[TestMethod]
		public void TestMethodA32()
		{
			//
			//	A.3.2.  Using some of the additional fields
			//
			string message = 
				@"Date:     26 Aug 76 1430 EDT
				From:     George Jones<Group@Host>
				Sender:   Secy@SHOST
				To:       ""Al Neuman""@Mad-Host,
						  Sam.Irving@Other-Host
				Message-ID:  <some.string@SHOST>";
		}

		[TestMethod]
		public void TestMethodA33()
		{
			//
			//	A.3.3. About as complex as you're going to get	
			//
			string message = 
				@"Date     :  27 Aug 76 0932 PDT
				From     :  Ken Davis <KDavis@This-Host.This-net>
				Subject  :  Re: The Syntax in the RFC
				Sender   :  KSecy@Other-Host
				Reply-To :  Sam.Irving@Reg.Organization
				To       :  George Jones <Group@Some-Reg.An-Org>,
				            Al.Neuman@MAD.Publisher
				cc       :  Important folk:
				              Tom Softwood <Balsa@Tree.Root>,
				              ""Sam Irving""@Other-Host;,
				            Standard Distribution:
				              /main/davis/people/standard@Other-Host,
				              ""<Jones>standard.dist.3""@Tops-20-Host>;
				Comment  :  Sam is away on business. He asked me to handle
				            his mail for him.  He'll be able to provide  a
				            more  accurate  explanation  when  he  returns
				            next week.
				In-Reply-To: <some.string@DBM.Group>, George's message
				X-Special-action:  This is a sample of user-defined field-
				            names.  There could also be a field-name
				            ""Special-action"", but its name might later be
				            preempted
				Message-ID: <4231.629.XYzi-What@Other-Host>";

		}
	}
}
